package vh.android.multiconnector.quiz.ui.dialogs;

import vh.android.multiconnector.quiz.GameAdminActivity;
import vh.android.multiconnector.quiz.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CreateGameDialogFragment extends DialogFragment {

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		// Get the layout inflater
		LayoutInflater inflater = getActivity().getLayoutInflater();

		builder.setTitle(getText(R.string.create_game_dialog_title));
		// Inflate and set the layout for the dialog
		// Pass null as the parent view because its going in the dialog layout
		final View v = inflater.inflate(R.layout.dialog_create_game, null);
		builder.setView(v)
				// Add action buttons
				.setPositiveButton(android.R.string.ok,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int id) {
								EditText edName = (EditText) v
										.findViewById(R.id.edGameName);
								if (edName.getText().toString().trim().length() == 0) {
									Toast.makeText(getActivity(),
											"Kidding?! Use at least 1 char!",
											Toast.LENGTH_SHORT).show();
									return;
								}
								Toast.makeText(getActivity(),
										"TODO Create Game", Toast.LENGTH_SHORT)
										.show();
								Intent intent = new Intent(getActivity()
										.getBaseContext(),
										GameAdminActivity.class);
								startActivity(intent);
							}
						})
				.setNegativeButton(android.R.string.cancel,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.dismiss();
							}
						});
		return builder.create();
	}
}
